package com.ss.android.image;

import android.content.Context;

import com.bytedance.common.utility.UIUtils;
import com.bytedance.common.utility.io.NetHackDbg;
import com.ss.android.article.browser.R;
import com.ss.android.common.app.permission.PermissionsResultAction;
import com.ss.android.common.util.ToolUtils;

import java.io.File;

final class f extends PermissionsResultAction {
    private final BaseImageManager mImageMgr;
    private final Context mContext;
    private final String b;
    private final String c;
    private final String d;
    private final File e;

    f(BaseImageManager baseImageManager, Context context, String arg3, String arg4, String arg5, File arg6) {
        this.mImageMgr = baseImageManager;
        this.mContext = context;
        this.b = arg3;
        this.c = arg4;
        this.d = arg5;
        this.e = arg6;
    }

    public final void onGranted() {
        if (!BaseImageManager.isExternalStorageMounted()) {
            UIUtils.showImageToast(this.mContext, R.drawable.close_popup_textpage, R.string.toast_download_sdcard_unavail);
        } else {
            String v1 = this.d + BaseImageManager.getSuffix(this.b, this.c);
            String v2 = this.mImageMgr.mExternalFunnyImageDir;
            String v0 = v2.endsWith("/") ? v2 + v1 : v2 + "/" + v1;
            File v3 = new File(v0);
            if ((v3.isFile()) && this.e.length() == v3.length()) {
                UIUtils.showImageToast(this.mContext, R.drawable.doneicon_popup_textpage, R.string.toast_download_successful);
                return;
            }

            if (!NetHackDbg.a(NetHackDbg.a(this.b), v2, v1)) {
                UIUtils.showImageToast(this.mContext, R.drawable.close_popup_textpage, R.string.toast_download_failed);
                return;
            }
            ToolUtils.sendMediaScannerScanFileBroadcast(this.mContext, v0);
            UIUtils.showImageToast(this.mContext, R.drawable.doneicon_popup_textpage, R.string.toast_download_successful);
        }
    }

    public final void onDenied(String arg1) {
    }
}

